package scau.mis4.chanyulin.atm.view;

import javafx.scene.Cursor;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import scau.mis4.chanyulin.atm.APP;
import scau.mis4.chanyulin.atm.base.common.PATH;
import scau.mis4.chanyulin.atm.base.utils.UiUtils;
import scau.mis4.chanyulin.atm.domain.Receipt;
import java.util.List;

/**
 * Created by chanyulin on 2018/4/28.
 * 凭条打印机图形
 */
public class ReceiptPrinterView extends ImageView {

    // 图片资源
    private final Image RECEIPT_EMPTY_IMG = UiUtils.getImage(PATH.RECEIPT_PRINTER_EMPTY_IMG_PATH);
    private final Image RECEIPT_EJECT_IMG = UiUtils.getImage(PATH.RECEIPT_PRINTER_EJECT_IMG_PATH);

    public ReceiptPrinterView() {
        this.setImage(RECEIPT_EMPTY_IMG);
        this.setCursor(Cursor.HAND);
        this.setOnMouseClicked(e -> {
            takeReceipts();
        });
    }

    /**
     * 获取取打印凭条
     */
    public void takeReceipts() {
        List<Receipt> receiptList = APP.ATM.takeReceiptsHandler();
        if (null == receiptList || 0 == receiptList.size()) return;
        for (Receipt r : receiptList) {
            APP.customerBagView.addReceipt(r);
        }
        this.setImage(RECEIPT_EMPTY_IMG);
        this.takeAllReceiptsSuccessCallBack();
    }

    /**
     * 凭条打印成功后回调此方法
     */
    public void printReceiptSuccessCallBack() {
        this.setImage(RECEIPT_EJECT_IMG);
    }

    /**
     * 取走凭条后回调此方法
     */
    public void takeAllReceiptsSuccessCallBack() {
        this.setImage(RECEIPT_EMPTY_IMG);
    }

}
